<?php
	require_once("userclass.php");
	$objUser = new userClass();
	
	require_once("paymentclass.php");
	$objPayment = new paymentClass();
	
	require_once("packageclass.php");
	$objPackage = new packageClass();
	
	
	global $wpdb;
	$table_name = $wpdb->prefix . "spec_checkout";
?>

<script type="text/javascript">
	/* <![CDATA[ */
	jQuery(document).ready(function(){
		jQuery('#memberlist').dataTable();
	});
	/* ]]> */

</script>


<div class="wrap">
    <h2>Payment Details &nbsp;&nbsp;<a class="button add-new-h2" href="admin.php?page=package_add&act=add">Add New</a></h2>
	 <table class="wp-list-table widefat fixed " id="memberlist">
		<thead>
			<tr>
				<th width="60"><u>Order ID</u></th>
				<th width="100"><u>User</u></th>
                <th ><u>Address</u></th>
                <th width="250"><u>Packages</u></th>
				<th width="60"><u>Total Amount </u></th>
				<th width="100"><u>Payment Status</u></th>
				
				<th>Time</th>
			</tr>
		</thead>
		<tbody>
<?php
		$sql = "select * from ".$table_name." ORDER BY  `id` DESC ";
		$result = mysql_query($sql) or die ('Error, query failed');
		if (mysql_num_rows($result) > 0 )
		{
		?>
				<script type="text/javascript">
				/* <![CDATA[ */
				jQuery(document).ready(function(){
					jQuery('#mytable').dataTable();
				});
				/* ]]> */

			</script>
<?php
			while ($row = mysql_fetch_assoc($result))
			{
				$package_name	     = '';
				$id       		 	 = $row['id'];
				$user_id     		 = $row['user_id'];
				$package_ids		 = $row['package_ids'];	
				
				# User DATA
				$user_info = get_userdata($user_id);
				# USer Details
   				$name =  $user_info->first_name.' '.$user_info->last_name ;
				$address = $user_info->address.'<br>';
				$city 	 = $user_info->city;
				$state	 = $user_info->state;
				$zip	 = $user_info->zip;
				$add     = $address. ' '.$city. ' '.$state. ' '.$zip;
				# Purchase
				$total_amount    	 = $row['total_amount'];
				
				$pkg_ids = explode("-", $package_ids);
					foreach($pkg_ids as $vals){
						$objPackage->getPackageDetails($vals);
						$package_name.= $objPackage->name.'<br>'; 
						}
						
				$status 	 = $objPayment->getPaymentStatus($row['payment_status']);
				$payment_message     = $row['payment_message'];
				
				$time				 = $row['time']; 
	?>
			<tr>
				<td>#<?php echo $id; ?></td>
				<td nowrap><?php echo $name; ?></td>
                <td nowrap><?php echo $add; ?></td>
                <td nowrap><?php echo $package_name; ?></td>
				<td nowrap><?php echo $total_amount; ?>$</td>
				<td nowrap><?php echo $status; ?></td>
				<td nowrap><?php echo $time; ?></td>

			</tr>
<?php }
	} else { ?>
			<tr>
				<td>No Record Found!</td>
			<tr>
	<?php } ?>
	</tbody>
	</table>
</div>